<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
 <%@ include file="/common/query.jsp"%>
<%@ include file="/common/det.jsp"%>
<script>
        $(function(){
            init();
        });
        function init(){
            var setting = {};
            var url ="";
            var p_insert = false;
            var p_del = false;

            var productCategoryId = getQueryStringByDecode("productCategoryId");
            //crudDefaultInputWidth = "250px";
            crudDialogWidth = 300;
            var columns = [
                {field:'id',title:'id',hidden:true},
                {field:'productAttrGroupName',title:'名称'
					/*,
                    dialog:{
                        mapper:{name:"分组名"},
                        url:"${base}/product/attr/group?select=true&singleSelect=true",
                        width:300,
                        height:300,
                        select:function(iframe){
                            var row = iframe.getGridChecked()[0];
                            $('#crud-productAttrGroupId').val(row.id);
                            $('#crud-productAttrGroupName').val(row.name);
                        }
                    }*/
				},
                {field:'productCategoryId',title:'分组ID',hidden:true,defaultValue:productCategoryId},
                {field:'productAttrGroupId',title:'属性分组ID',hidden:true}
            ];
            url='/product/category/attrgroup/manager?search_EQ_productCategoryId='+productCategoryId;
            //setting.singleSelec	t = true;
            createQuery('body',columns,
				{
				    pager:false,edit:true,editBtn:false,add:false,searchBar:{hidden:true},del:true,heji:false,xuhao:false,
					singleSelect:true,
                    onClickRow:function () {
                        seeProductCategoryAttrgroupAttr();
                    },

                    toolbar:[{
                        text : '<a  class="pure-button pure-button-primary" >添加</a>',
                        handler : function(){
                            layer.open({
                                type: 2,
                                title: "添加",
                                shadeClose: true,
                                shade: 0.8,
                                area: ['380px', '90%'],
                                content: "${base}/product/attr/group?select=true&singleSelect=false&productCategoryId="+productCategoryId, //iframe的url
                                btn:['确定'],
                                yes: function (index, layero) {
                                    var rows = $(layero).find("iframe")[0].contentWindow.getGridChecked();

                                    if(rows.length>0){
                                        var groupIds = "";
                                        for(var i =0 ;i<rows.length;i++){
                                            var row = rows[i];
                                            groupIds += ','+row.id;
										}
                                        groupIds = groupIds.substr(1);
                                        $.ajax({
                                            type : 'post',
                                            url : '${base}/product/category/attrgroup/batchAddAttrGroup',
                                            data : {
                                                productCategoryId:productCategoryId,
                                                ids:groupIds
                                            },
											async:false,
                                            dataType : 'json',
                                            success :  function(res){
                                                if(res.code==-1){
                                                    alert(res.msg);
                                                }else{
                                                    search();
                                                }
                                            }
                                        })
									}
                                    layer.close(index);
                                },
                            });

                        }
                    }]


				},
				url);
        };

        function seeProductCategoryAttrgroupAttr() {
                var row = getGridSelected();
                window.parent.seeProductCategoryAttrgroupAttr(row);
        }

</script>
</head>
<body>
	  <div id="body"></div>
</body>
</html>